package com.xiyu.service.controller.admin.infra.devops;
import com.xiyu.service.vo.infra.devops.projectVersion.ProjectVersionGetByProjectOutput;
import com.xiyu.service.vo.infra.devops.projectVersion.ProjectVersionSingleGetOutput;
import com.xiyu.service.framework.web.web.core.pojo.CommonResult;
import com.xiyu.service.framework.web.web.core.pojo.PageResult;
import com.xiyu.service.vo.infra.devops.projectVersion.ProjectVersionUpdateInput;
import com.xiyu.service.vo.infra.devops.projectVersion.ProjectVersionCreateInput;
import com.xiyu.service.vo.infra.devops.projectVersion.ProjectVersionPageQueryOutput;
import com.xiyu.service.vo.infra.devops.projectVersion.ProjectVersionPageQueryInput;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;

import com.xiyu.service.service.infra.devops.ProjectVersionService;

import java.util.List;

import static com.xiyu.service.framework.web.web.core.pojo.CommonResult.success;

@Tag(name = "项目版本管理")
@RestController
@RequestMapping("/infra/devops/project-version")
@Validated
public class ProjectVersionController {

    @Resource
    private ProjectVersionService projectVersionService;

    @GetMapping("/page-query")
    @Operation(summary = "分页查询项目版本")
    public CommonResult<PageResult<ProjectVersionPageQueryOutput>> pageQuery(@Valid ProjectVersionPageQueryInput inputVO) {
        return success(projectVersionService.pageQuery(inputVO));
    }

    @PostMapping("/create")
    @Operation(summary = "新增项目版本")
    public CommonResult<Long> create(@Valid @RequestBody ProjectVersionCreateInput inputVO) {
        return success(projectVersionService.create(inputVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新项目版本")
    public CommonResult<Boolean> update(@Valid @RequestBody ProjectVersionUpdateInput inputVO) {
        return success(projectVersionService.update(inputVO));
    }

    @DeleteMapping("/deleted")
    @Operation(summary = "删除客户版本")
    @Parameter(name = "id", description = "项目版本主键ID", example = "")
    public CommonResult<Boolean> deleted(@RequestParam("id") Long id) {
        return success(projectVersionService.deleted(id));
    }

    @GetMapping("/single-get")
    @Operation(summary = "获取单个客户版本")
    @Parameter(name = "id", description = "项目版本主键ID", example = "")
    public CommonResult<ProjectVersionSingleGetOutput> singleGet(@RequestParam("id") Long id) {
        return success(projectVersionService.singleGet(id));
    }

    @PostMapping("/get-by-project")
    @Operation(summary = "根据项目获取项目的所有版本")
    @Parameter(name = "projectId", description = "项目ID", example = "")
    public CommonResult<List<ProjectVersionGetByProjectOutput>> getByProject(@RequestParam("projectId") Long projectId) {
        return success(projectVersionService.getByProject(projectId));
    }

}
